package servlet.user;



import dao.UserDao;
import entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.Date;

@WebServlet("/servlet/myaccount")
public class MyAccountServlet extends HttpServlet{
    UserDao ud = new UserDao();

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
//        String tel =(String) request.getSession().getAttribute("TEL");
        //通过电话查询到用户信息
//        User u = ud.loadBytel("tel");
        User u = ud.loadBytel("18270608096");
        //获取到表单中的信息
        String username = request.getParameter("username");
        String gender = request.getParameter("gender");
        String address = request.getParameter("address");
        //Date date = (Date)request.getParameter("date");
        //给用户赋值
        u.setRealName(username);
        u.setGender(gender);
        u.setAddress(address);
        //修改数据库
        boolean result = ud.update(u);
        if(result){
            request.setAttribute("change","信息修改成功");
            request.getRequestDispatcher("/servlet/accountchange").forward(request , response );
        }else{
            request.setAttribute("change","信息修改失败");
            request.getRequestDispatcher("/servlet/accountchange").forward(request , response );
        }

    }
}
